<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Fundrising Controller.
 * 
 * @class     Fundrising
 * @author    Iqbal
 * @version   1.0.0
 * @copyright Copyright (c) 2014 IPPI (http://www.ippi.or.id)
 */
class fundrising extends CI_Controller {
    /**
	 * Constructor.
	 */
    function __construct() {
        parent::__construct();
        
        // Load model
        $this->load->model('model_fundrising', 'm_fundrising', TRUE);
    }
    
    /**
	 * Load Product of fundrising Data function.
     * 
     * @param[in] int $offset Offset of Table Product data
     * 
     * @return AJAX String
	 */
    function product_data($offset=0){
        // Set variables
        $limit          = get_option('fundrising_limit');
        $condition      = '';
        $order_by       = '';
        
        // Search Event
        $search_val     = trim( ippi_isset($this->input->get('search_val'), '') );
        if( !empty($search_val) ) {
            $f          = '%product_name% LIKE "%%s%%"';
            $condition .= str_replace('%s%', $search_val, $f);
        }
        
        // Filter Event
        $filter         = ippi_isset($this->input->get('search_fil'), '');
        if( !empty($filter) ) {
            if( $filter == 'product_terbaru' ){
                $order_by  .= '%datecreated% DESC';
            }elseif( $filter == 'alfabet_az' ){
                $order_by  .= '%product_name% ASC';
            }elseif( $filter == 'alfabet_za' ){
                $order_by  .= '%product_name% DESC';
            }elseif( $filter == 'harga_termurah' ){
                $order_by  .= '%price% ASC';
            }elseif( $filter == 'harga_termahal' ){
                $order_by  .= '%price% DESC';
            }
        }
        
        // Get products data
        $products           = $this->m_fundrising->get_all_products_data($limit, $offset, $condition, $order_by);
        $product            = '';
        $pagination         = '';
        
        // Check response of get product data
        if( !empty($products) ){
            $total          = ippi_get_last_found_rows();
            
            foreach($products as $row){
                if($row->stock == 0){
                    $buy    = '<a class="btn btn-primary btn-sm buy" href="'.base_url() . 'fundrising/addtocart/'.$row->product_id.'" disabled="disabled">Habis</a>';
                }elseif($row->stock > 0){
                    $buy    = '<a class="btn btn-primary btn-sm buy" href="'.base_url() . 'fundrising/addtocart/'.$row->product_id.'">Beli</a>';
                }
                
                $product   .= '
                <li class="col-md-4">
                    <div class="thumbnail">
                        <div class="media-wrap">
                            <div class="media-inner">
                                <div class="border-transparent1">
                                    <div class="overlay-hover">
                                        <div class="overlay-content">
                                            <a href="'. base_url() . "fundrising/productdetails/" . $row->product_id.'" class="glyphicon icon-show product_details" data-id="'.$row->product_id.'"></a>
                                        </div>
                                    </div>
                                </div>
                                '. ( !empty($row->path) && file_exists($row->path)  ? '<img src="'. base_url() . $row->path .'" alt="'.$row->product_name.'" />' : '<img src="' . base_url('content/product/noimage.jpg') . '" alt="No Image" />' ) .'
                            </div>
                        </div>
                        <div class="caption">
                            <div class="caption-inner">
                                <a href="'. base_url() . "fundrising/productdetails/" . $row->product_id.'" class="caption-title h5 product_details_title" data-id="'.$row->product_id.'">'. $row->product_name .'</a>
                                <span class="caption-meta">
                                    <label style="margin-bottom: 0px; padding: 2px 0;">Rp '. number_format($row->price, 0, "", ".") .'</label>
                                    <span class="pull-right">'.$buy.'</span>
                                </span>
                            </div>
                        </div>
                    </div>
                </li>';
            }
            
            // Set pagination
            if ($total > $limit){
                $this->load->library('pagination');
                
                $config['base_url']     = 'fundrising/product_data/';
                $config['total_rows']   = $total;
                $config['per_page']     = $limit; 
                $config['anchor_class'] = 'class="pagination_fundrising" ';
                
                $this->pagination->initialize($config);
                $pagination             = $this->pagination->create_links(); 
            }
        }else{
            $product       .= '
            <li class="col-md-12">
                <div class="show-more">
                    <div class="show-more-inner text-center">
                        <a href="#" class="btn-showmore btn btn-primary btn-sm disabled">No Product</a>
                    </div>
                </div>
            </li>';
        }
        
        // Set JSON data
        $data = array(
            'products'      => $product,
            'pagination'    => $pagination
        );
        
        // JSON encode data
        die(json_encode($data));
    }
    
    /**
	 * Load Product Details function.
     * 
     * @param[in] int $id Product ID
     * 
     * @return AJAX String
	 */
    function productdetails($id=0){
        // Get Product Data
        $product = $this->m_fundrising->get_productdata($id);
        // Check for response get product
        if( !empty($product) ){
            // Set Variables
            if($product->stock == 0){
                $stock  = '<div class="alert alert-danger" style="display: inline-block;">Stock Habis</div>';
                $buy    = '<div class="btn btn-primary" disabled="disabled">Habis</div>';
            }elseif($product->stock > 0){
                $stock  = '<div class="alert alert-success" style="display: inline-block;">Stock Tersedia</div>';
                $buy    = '<a href="'.base_url() . 'fundrising/addtocart/'.$product->product_id.'" class="btn btn-default btn-buy">Beli</a>';
            }
            // Set New Object of Product
            $product->stock_text    = $stock;
            $product->btn_buy       = $buy;
            
            // Get Product Images
            $product_image      = $this->m_fundrising->get_product_image($id);
            // Set Data View
            $data               = array(
                'product'       => $product,
                'product_id'    => $id,
                'product_image' => $product_image
            );
            // Set View
            $this->load->view('front/welcome/welcome_fundrising_details',$data);
        }
    }
    
    /**
	 * Add To Cart function.
     * 
     * @param[in] int $product_id Product ID
     * 
     * @return AJAX String
	 */
    function addtocart($product_id=0){
        // Get Product Data
        $product        = $this->m_fundrising->get_productdata($product_id);
        // Set Quantity of Product
        $qty            = ippi_isset($this->input->post('qty'), 0);
        // Set empty variable
        $items          = '';
        $item_count     = '';
        $msg            = '';
        $stock          = 0;
        $cartqty        = 0;
        $update         = false;
        
        // Check response of get product data
        if( !empty($product) ){
            // Set Stock of Product
            $stock      = $product->stock;
            // Get Cart Contents
            $cart       = $this->cart->contents();
            
            // Check response of get cart data
            if( !empty($cart) ){
                foreach($cart as $row){
                    if($row['id'] == $product->product_sku){
                        $cartqty    = $row['qty'];
                        $qty        = $qty + $cartqty;
                    }
                }
            }
            
            // Check order with stock
            if( !empty($cartqty) && $cartqty >= $stock ){
                $msg    = '<div class="alert alert-info">Cart Anda sudah terisi product ini dengan quantity '.$cartqty.' product. Anda tidak bisa menambah pemesanan product lagi.</div>';
            }else{
                if($qty > $stock){
                    $msg    = '<div class="alert alert-info">Pemesanan Anda melebihi stock. Stock tersedia '.$stock.' product.</div>';
                }else{
                    // Set Invoice number
                    $invoice    = ippi_generate_rand_string(10);
                    // Set Item Array
                    $item       = array(
                        "id"            => $product->product_sku,
                        "name"          => $product->product_name, 
                        "qty"           => $qty,
                        "weight"        => $product->weight,
                        "price"         => absint($product->price),
                        "options"       => array(
                            "invoice"   => $invoice,
                            "prod_id"   => $product->product_id,
                        ),
                    );
                    
                    // Check response of get cart data
                    if( !empty($cart) ){
                        foreach($cart as $row){
                            if($row['id'] == $product->product_sku){
                                $qtyn   = array(
                                    'rowid' => $row['rowid'], 
                                    'qty'   => $qty
                                );
                                
                                $this->cart->update($qtyn);
                                $update = true;
                                break;
                            }
                        }
                        
                        if( !$update ){
                            $this->cart->insert($item);
                        }
                    }else{
                        $this->cart->insert($item);
                    }

                    $cart       = $this->cart->contents();
                    $i          = 0;
        
                    foreach($cart as $row){
                        $sub_amount = absint($row['qty']) * absint($row['price']);
                        $sub_amount = number_format($sub_amount, 0);
                        $items .= '
                        <div class="cart-list">
                            <div class="cart-title">'.$row['name'].'</div>
                            <div class="cart-content">
                                <div class="pull-right">
                                    <button class="btn btn-primary btn-xs update-item" data-url="'.base_url().'fundrising/updatecartitem/'.$row['rowid'].'">Update Cart</button>
                                    <button class="btn btn-default btn-xs remove-item" data-url="'.base_url().'fundrising/removecartitem/'.$row['rowid'].'">Remove</button>
                                </div>
                                <input type="number" id="cart_qty" name="cart_qty" class="cart-qty" autocomplete="off" value="'.$row['qty'].'" onkeypress="return isNumber(event)" min="0" step="1" />  
                                x Rp '.number_format($row['price'],0).' = <strong>Rp '.$sub_amount.'</strong>
                            </div>
                        </div>';
                        $i++;
                    }
                    
                    $total       = $this->cart->total();
                    $total       = number_format($total, 0);
                    $items      .= '
                    <div class="cart-total">
                        Total : Rp '.$total.' <button class="btn btn-default btn-sm" id="btn_checkout">Lanjut Ke Pembayaran</button>
                    </div>';
                    
                    $item_count  = $i . ' item(s) : Rp ' . $total;   
                }
            }
        }
        
        // Set JSON data
        $data = array(
            'items'         => $items,
            'item_count'    => $item_count,
            'message'       => $msg,
            'stock'         => $stock,
        );
    
        // JSON encode data
        die(json_encode($data));
    }
    
    /**
	 * Cart List function.
     * 
     * @return AJAX String
	 */
    function cartlist(){
        // Set empty variable
        $items          = '';
        $item_count     = '';
        $update         = false;
        
        // Get Cart Contents
        $cart           = $this->cart->contents();
        
        // Check response of get product data
        if( !empty($cart) ){
            $i          = 0;
            foreach($cart as $row){
                $sub_amount = absint($row['qty']) * absint($row['price']);
                $sub_amount = number_format($sub_amount, 0);
                $items .= '
                <div class="cart-list">
                    <div class="cart-title">'.$row['name'].'</div>
                    <div class="cart-content">
                        <div class="pull-right">
                            <button class="btn btn-primary btn-xs update-item" data-url="'.base_url().'fundrising/updatecartitem/'.$row['rowid'].'">Update Cart</button>
                            <button class="btn btn-default btn-xs remove-item" data-url="'.base_url().'fundrising/removecartitem/'.$row['rowid'].'">Remove</button>
                        </div>
                        <input type="number" id="cart_qty" name="cart_qty" class="cart-qty" autocomplete="off" value="'.$row['qty'].'" onkeypress="return isNumber(event)" min="0" step="1" /> 
                        x Rp '.number_format($row['price'],0).' = <strong>Rp '.$sub_amount.'</strong>
                    </div>
                </div>';
                $i++;
            }
            
            $total       = $this->cart->total();
            $total       = number_format($total, 0);
            $items      .= '
            <div class="cart-total">
                Total : Rp '.$total.' <button class="btn btn-default btn-sm" id="btn_checkout">Lanjut Ke Pembayaran</button>
            </div>';
            
            $item_count  = $i . ' item(s) : Rp ' . $total;
        }else{
            $items      .= '
            <p style="margin-bottom: 5px;">Keranjang belanja Anda masih kosong. Silahkan pilih product kami di bawah. Selamat Berbelanja!</p>
            <button class="btn btn-default btn-sm" id="continue-shopping">Lanjut Belanja</button>';
            
            $item_count  = '(Kosong)';
        }
        
        // Set JSON data
        $data = array(
            'items'         => $items,
            'item_count'    => $item_count
        );

        // JSON encode data
        die(json_encode($data));
    }
    
    /**
	 * Cart List Review function.
     * 
     * @return AJAX String
	 */
    function cartlistreview(){
        // Set empty variable
        $items          = '';
        $item_count     = '';
        $update         = false;
        
        // Get Cart Contents
        $cart           = $this->cart->contents();
        $paket          = ippi_isset($this->input->post('paket'), '');
        $paket          = explode('-', $paket);
        
        // Check response of get product data
        if( !empty($cart) ){
            $i          = 0;
            foreach($cart as $row){
                $sub_amount = absint($row['qty']) * absint($row['price']);
                $sub_amount = number_format($sub_amount, 0);
                $items .= '
                <div class="col-md-12 cart-list">
                    <div class="row">
                        <div class="col-md-6 cart-title">'.$row['name'].'</div>
                        <div class="col-md-6 cart-content text-right">
                            '.$row['qty'].' x Rp '.number_format($row['price'],0).' = Rp '.$sub_amount.'
                        </div>
                    </div>
                </div>';
                $i++;
            }
            
            $subtotal   = $this->cart->total();
            $subtotal   = number_format($subtotal, 0);
            $items     .= '<div class="cart-subtotal text-right">Subtotal = <strong>Rp '.$subtotal.'</strong></div>';
            
            $shipping   = number_format(absint($paket[1]), 0);
            $items     .= '<div class="cart-subtotal text-right">Biaya Pengiriman JNE ('.strtoupper($paket[0]).') = <strong>Rp '.$shipping.'</strong></div>';
            
            $total      = $this->cart->total() + absint($paket[1]);
            $total      = number_format($total, 0);
            $items     .= '<div class="cart-total text-right">Total Rp '.$total.'</strong></div>';
        }else{
            $items     .= '
            <p style="margin-bottom: 5px;">Keranjang belanja Anda masih kosong. Silahkan pilih product kami di bawah. Selamat Berbelanja!</p>
            <button class="btn btn-default btn-sm" id="continue-shopping">Lanjut Belanja</button>';
        }
        
        // Set JSON data
        $data = array(
            'items'         => $items,
        );

        // JSON encode data
        die(json_encode($data));
    }
    
    /**
	 * Remove Cart Item function.
     * 
     * @param[in] string $rowid Cart row ID
     * 
     * @return AJAX String
	 */
    function removecartitem($rowid=''){
        $data = array(
            'rowid'     => $rowid,
            'qty'       => 0,
            'weight'    => 0,
            'price'     => 0,
        );

        $this->cart->update($data);
        die('removed');
    }
    
    /**
	 * Update Cart Item function.
     * 
     * @param[in] string $rowid Cart row ID
     * 
     * @return AJAX String
	 */
    function updatecartitem($rowid=''){
        // Set Empty variable
        $message    = '';
        $stock      = 0;
        $updated    = false;
        // Get Cart Options
        $cart       = $this->cart->product_options($rowid);
        // Check Cart Options value
        if( !empty($cart) ){
            // Set Product ID from Cart Options
            $product_id = $cart['prod_id'];
            // Get Product Data
            $product    = $this->m_fundrising->get_productdata($product_id);
            // Set Stock of product
            $stock      = $product->stock;
            // Set Quantity
            $qty        = ippi_isset($this->input->post('qty'), 0);
            // Check Quantity with stock
            if($qty > $stock){
                $message        = '<div class="alert alert-info">Pemesanan Anda melebihi stock. Stock tersedia '.$stock.' product.</div>';
            }else{
                $data           = array(
                    'rowid'     => $rowid,
                    'qty'       => $qty,
                );
                $this->cart->update($data);
                $updated        = true;
            }
        }
        
        // Set JSON data
        $data = array(
            'update'    => $updated,
            'message'   => $message,
            'stock'     => $stock,
        );

        // JSON encode data
        die(json_encode($data));
    }
    
    /**
	 * Get From Shipping City function.
     * 
     * @return AJAX String
	 */
    function cityfrom(){        
        // Set variables
        $return_arr     = array();
        $response       = array();
        $term           = ippi_isset($this->input->post('search'), '');

        // Get City
        $cities     = $this->m_fundrising->get_tarif(trim($term));
        
        if( !empty($cities) ){
            foreach ($cities as $row) {
                $row_array['id']            = $row->id_tarif;
                $row_array['name']          = strval(strtoupper($row->kota . ' - ' . $row->kecamatan));
                array_push($return_arr,$row_array);
            }
            
            $response['success']            = true;
            $response['tarif']              = $return_arr;
            echo json_encode($response);
            die();   
        }

        $row_array['id']            = '';
        $row_array['name']          = '';
        array_push($return_arr,$row_array);
        
        $response['success']        = false;
        $response['tarif']          = $return_arr;
        echo json_encode($response);
    }
    
    /**
	 * Count Shipping Fee.
     * 
     * @return AJAX String
	 */
    function counttarif(){
        // Set Tarif Data
        $weight         = 0;
        $paket          = array();
        $response       = array();
        $id_tarif       = ippi_isset($this->input->post('id'), '');
        $tarifdata      = $this->m_fundrising->get_all_tarif_data(true, 0,0,'%id_tarif% = '.$id_tarif.'', '');
        
        if( !empty($tarifdata) ){
            // Get Cart Contents
            $cartdata   = $this->cart->contents();
            foreach($cartdata as $cart){
                $weight = $weight + ( absint($cart['weight']) * absint($cart['qty']) );
            }
            
            if( $tarifdata->reguler > 0 )   $paket['reguler']   = absint($tarifdata->reguler) * $weight;
            if( $tarifdata->oke > 0 )       $paket['oke']       = absint($tarifdata->oke) * $weight;
            if( $tarifdata->yes > 0 )       $paket['yes']       = absint($tarifdata->yes) * $weight;
            
            $option         = '';
            foreach( $paket as $key => $value ){
                $option    .= '<option value="'.$key.'-'.$value.'">' . strtoupper($key) . ' - Rp ' . number_format($value, 0) . '</option>';
            }
            
            $response['paket'] = $option;
        }
        
        echo json_encode($response);
    }
    
    /**
	 * Order Function.
     * 
     * @return AJAX String
	 */
    function order(){
        // Set Response
        $response               = array();
        
        // Billing Information
        $order_name             = ippi_isset($this->input->post('co_nama'), '');
        $order_email            = ippi_isset($this->input->post('co_email'), '');
        $order_propinsi         = ippi_isset($this->input->post('co_propinsi'), '');
        $order_kota             = ippi_isset($this->input->post('co_kota'), '');
        $order_alamat           = ippi_isset($this->input->post('co_alamat'), '');
        $order_kodepos          = ippi_isset($this->input->post('co_kodepos'), '');
        $order_phone            = ippi_isset($this->input->post('co_phone'), '');
        
        // Shipping Option
        $order_ship             = ippi_isset($this->input->post('co_ship'), '');
        
        // Shipping Information
        $order_name_ship        = ippi_isset($this->input->post('cos_nama'), '');
        $order_propinsi_ship    = ippi_isset($this->input->post('cos_propinsi'), '');
        $order_kota_ship        = ippi_isset($this->input->post('cos_kota'), '');
        $order_alamat_ship      = ippi_isset($this->input->post('cos_alamat'), '');
        $order_kodepos_ship     = ippi_isset($this->input->post('cos_kodepos'), '');
        $order_phone_ship       = ippi_isset($this->input->post('cos_phone'), '');
        
        // Payment Information
        $order_payment          = ippi_isset($this->input->post('co_payment'), '');
        $order_cityto           = ippi_isset($this->input->post('co_cityto'), '');
        $order_paket            = ippi_isset($this->input->post('co_paket'), '');

        $this->form_validation->set_rules('co_nama','Nama','required');
        $this->form_validation->set_rules('co_email','Email','required|email');
        $this->form_validation->set_rules('co_propinsi','Propinsi','required');
        $this->form_validation->set_rules('co_kota','Kota','required');
        $this->form_validation->set_rules('co_alamat','Alamat','required');
        $this->form_validation->set_rules('co_kodepos','Kode POS','required');
        $this->form_validation->set_rules('co_phone','Phone','required');
        
        if( $order_ship == "ship_diff" ){
            $this->form_validation->set_rules('cos_nama','Shipping Nama','required');
            $this->form_validation->set_rules('cos_propinsi','Shipping Propinsi','required');
            $this->form_validation->set_rules('cos_kota','Shipping Kota','required');
            $this->form_validation->set_rules('cos_alamat','Shipping Alamat','required');
            $this->form_validation->set_rules('cos_kodepos','Shipping Kode POS','required');
            $this->form_validation->set_rules('cos_phone','Shipping Phone','required');
        }
        
        $this->form_validation->set_rules('co_payment','Payment Type','required');
        $this->form_validation->set_rules('co_cityto','Kota Tujuan','required');
        $this->form_validation->set_rules('co_paket','Paket','required');
        
        if($this->form_validation->run() == FALSE){
            $response = array(
                'order'     => false, 
                'message'   => '<div class="alert alert-info">Order tidak berhasil, ada kesalahan dalam data order Anda</div>',
                'invoice'   => '',
            );
            echo json_encode($response); die();
        }else{
            $invoice                = 'INV-' . ippi_generate_rand_string(10);
            $curdate                = date("Y-m-d H:i:s");
            $order_paket            = explode('-', $order_paket);
            $order_id               = 0;
            
            $order_data             = array(
                'invoice'           => $invoice,
                'member_id'         => ippi_get_current_member_id(),
                'billing_email'     => $order_email,
                'billing_name'      => $order_name,
                'billing_phone'     => $order_phone,
                'billing_province'  => $order_propinsi,
                'billing_city'      => $order_kota,
                'billing_address'   => $order_alamat,
                'billing_zipcode'   => $order_kodepos,
                'shipping_name'     => $order_name_ship,
                'shipping_phone'    => $order_phone_ship,
                'shipping_province' => $order_propinsi_ship,
                'shipping_city'     => $order_kota_ship,
                'shipping_address'  => $order_alamat_ship,
                'shipping_zipcode'  => $order_kodepos_ship,
                'shipping_paket'    => strtoupper($order_paket[0]),
                'shipping_to'       => trim($order_cityto),
                'shipping_amount'   => absint($order_paket[1]),
                'amount'            => $this->cart->total(),
                'payment'           => $order_payment,
                'time'              => $curdate,
                'datecreated'       => $curdate,
                'datemodified'      => $curdate,
            );
            
            if( $order_id = $this->m_fundrising->save_order($order_data) ){
                // Get Cart Contents
                $cart               = $this->cart->contents();
                // Check response of get product data
                if( !empty($cart) ){
                    foreach($cart as $row){
                        $item               = array(
                            'order_id'      => $order_id,
                            'product_id'    => $row['options']['prod_id'],
                            'qty'           => $row['qty'],
                            'amount'        => $row['price'],
                        );
                        $this->m_fundrising->save_order_item($item);
                    }
                }
                
                $this->cart->destroy();
                
                $response = array(
                    'order'     => true, 
                    'message'   => '<div class="alert alert-success">Order berhasil, silahkan transfer ke rekening di bawah dan lakukan konfirmasi.',
                    'invoice'   => $invoice,
                );
                echo json_encode($response); die();
            }
        }
    }
    
    /**
	 * Order Confirm Function.
     * 
     * @return AJAX String
	 */
    function orderconfirm(){
        // Set Response
        $response               = array();
        
        // Billing Information
        $confirm_invoice        = ippi_isset($this->input->post('oc_invoice'), '');
        $confirm_email          = ippi_isset($this->input->post('oc_email'), '');
        $confirm_amount         = ippi_isset($this->input->post('oc_amount'), '');
        $confirm_payment        = ippi_isset($this->input->post('oc_payment'), '');
        $confirm_bank_form      = ippi_isset($this->input->post('oc_bank_from'), '');
        $confirm_rek_from       = ippi_isset($this->input->post('oc_rek_from'), '');
        $confirm_note           = ippi_isset($this->input->post('oc_note'), '');
        
        // Check Order By Invoice
        $order_data             = $this->m_fundrising->get_order_by('invoice', trim($confirm_invoice));
        
        if( !$order_data || empty($order_data) ){
            $response           = array(
                'confirm'       => false, 
                'message'       => '<div class="alert alert-info">Invoice order tidak terdaftar, silahkan masukkan invoice yang lain.</div>',
            );
            echo json_encode($response); die();
        }else{
            $order_amount       = absint($order_data->amount) + absint($order_data->shipping_amount);
            $curdate            = date('Y-m-d H:i:s');
            
            if( absint($confirm_amount) != $order_amount ){
                $response       = array(
                    'confirm'   => false, 
                    'message'   => '<div class="alert alert-info">Jumlah pembayaran tidak sesuai dengan jumlah biaya order.</div>',
                );
                echo json_encode($response); die();
            }
            
            if( $order_data->status > 0 ){
                $response       = array(
                    'confirm'   => false, 
                    'message'   => '<div class="alert alert-info">Invoice order sudah di konfirmasi</div>',
                );
                echo json_encode($response); die();
            }
            
            $data_confirm           = array(
                'order_id'          => $order_data->order_id,
                'invoice'           => $order_data->invoice,
                'member_id'         => ippi_get_current_member_id(),
                'email'             => trim($confirm_email),
                'amount'            => absint($confirm_amount),
                'time'              => $curdate,
                'purchase_type'     => trim($confirm_payment),
                'bank_from'         => trim($confirm_bank_form),
                'bank_account_from' => trim($confirm_rek_from),
                'note'              => trim($confirm_note),
                'datecreated'       => $curdate,
                'datemodified'      => $curdate,
            );
            
            if( $save_confirm_id = $this->m_fundrising->save_order_confirm($data_confirm) ){
                if( $this->m_fundrising->update_data($order_data->order_id, array('status' => 2)) ){
                    $response       = array(
                        'confirm'   => true, 
                        'message'   => '<div class="alert alert-success">Confirm order berhasil.</div>',
                    );
                    echo json_encode($response); die();
                } 
            }
            
            $response           = array(
                'confirm'       => false, 
                'message'       => '<div class="alert alert-info">Confirm order tidak berhasil</div>',
            );
            echo json_encode($response); die();
        }
    }
}

/* End of file fundrising.php */
/* Location: ./application/controllers/fundrising.php */